package cn.jbit.generatedbdata.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

/**
 * @author 张在成
 */
@Configuration
public class ESConfig {

    public  static final RequestOptions CommonOptions;



    static {
        RequestOptions.Builder builder=RequestOptions.DEFAULT.toBuilder();

        CommonOptions=builder.build();
    }

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestClientBuilder clientBuilder= RestClient.builder(new HttpHost("192.168.43.46",9200,"http"));
        return new RestHighLevelClient(clientBuilder);
    }

    @Bean(name = { "elasticsearchOperations", "elasticsearchRestTemplate" })
    public ElasticsearchRestTemplate elasticsearchTemplate() {
        return new ElasticsearchRestTemplate(restHighLevelClient());
    }


}
